package com.emailsystem.emailsystem.service.impl.server;

import com.emailsystem.emailsystem.service.ServerService;
import org.springframework.stereotype.Service;

import java.net.ServerSocket;
import java.net.Socket;

@Service
public class ServerServiceImpl implements ServerService {

    public static boolean isOn=false;
    @Override
    public void runServer(){

        try {
            System.out.println("Socket服务器开始运行...");
            ServerSocket serverSocket = new ServerSocket(9090);
            ServerServiceImpl.isOn=true;
            while (true){
                Socket socket = serverSocket.accept();
                new Thread(new Server_listen(socket)).start();
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
    @Override
    public boolean getServerStatus(){
        return ServerServiceImpl.isOn;
    }

}

